module.exports = app => {
  const mongoose = app.mongoose
  const { Schema } = mongoose
  const { ObjectId } = Schema

  const modelSchema = new Schema({
      path: { type: String, remark: '请求路径' },
      state: { type: Number, remark: '请求状态' },
      method: { type: Number, enum: { 1: 'GET', 2: 'POST', 3: 'PUT', 4: 'DELETE', 5: 'OTHER' }, remark: '请求方法' },
      username: { type: String, remark: '访问用户名' },
      user: { type: ObjectId, ref: 'user', remark: '用户' },
      spm: { type: Number, enum: { 1: 'Application', 2: '管理系统', 3: '其他' }, remark: '来源' },
    },
    {
      collections: 'log',
      timestamps:
        true,
    },
  )

  modelSchema.index({ path: 1 })
  modelSchema.index({ spm: 1 })

  return mongoose.model('log', modelSchema)
}